###############################################################################
#
# Copyright (c) 2005 by L&M
#
# GNU General Public Licence (GPL)
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA  02111-1307  USA
#
###############################################################################
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.Message import Message
from Products.LMSkin.htmlrender import renderHTML

from Products.CMFCore.utils import getToolByName

from StringIO import StringIO
import string

def sendNotificationMail(self,message):
    #TITULO DO EMAIL
    subject = 'Informativo LM'

    plone_utils = getToolByName(self, 'plone_utils')
    portal_membership = getToolByName(self, 'portal_membership')
    usuarios = portal_membership.listMemberIds()

    fromEmail = "Leonardo Miranda<contatoo@leonardomiranda.com.br>"

    charset     = plone_utils.getSiteEncoding()

    email = MIMEMultipart('alternative')
    email.epilogue = ''

    textPart = MIMEText(message, 'plain', charset)
    email.attach(textPart)
    htmlPart = MIMEText(renderHTML(message), 'html', charset)
    email.attach(htmlPart)
    message = str(email)

    for u in usuarios:
        email = portal_membership.getMemberById(u).getProperty('email', '')
        try:
            self.MailHost.send(message = message,
                                mto = email,
                                mfrom = fromEmail,
                                subject = subject)   
        except:
            raise
        
    return resposta
